<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>在vue中使用插槽(slot)以及具名插槽</title>
    <script src="./js/vue.js"></script>
</head>
<body>
    <div id="root">
        <!-- <child content="<p>父组件传值</p>"></child> -->
        <!-- 使用插槽 -->
        <child>
            <p>vue</p>
        </child>
        <!-- 使用多个插槽 -->
        <body-content>
            <!-- 具名插槽 -->
            <div slot="header" class="header">header</div>
            <div slot="footer" class="footer">footer</div>
        </body-content>
    </div>
    <script>
        Vue.component('body-content', {
            template: `<div>
                            <slot name='header'></slot>           
                            <div class='content'>content</div>
                            <slot name='footer'></slot>
                       </div>`
        });
        Vue.component('child',{
            // props: ['content'],
            // template: `<div>
            //                 <p>hello vue</p>
            //                 <div v-html='this.content'></html><!-- 这样写会多出一个div标签>
            //            </div>`
            template: `<div>
                            <p>hello</p>
                            <slot>默认slot值，插槽没有内容时显示</slot>
                       </div>`


        });
        var vm = new Vue({
            el: "#root",
        });

    </script>
</body>
</html>